package cn.edu.gcu.lost.sys.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.gcu.lost.sys.dao.MenuDao;
import cn.edu.gcu.lost.sys.entity.Menu;

@Service
@Transactional(readOnly = true)
public class MenuService {

    @Autowired
    private MenuDao menuDao;

    public List<Menu> findList() {
        return menuDao.findAllList(new Menu());
    }

    @Transactional(readOnly = false)
    public boolean save(Menu menu) {
        int result = 0;
        if (StringUtils.isBlank(menu.getId())) {
            menu.preInsert();
            result = menuDao.insert(menu);
        } else {
            menu.preUpdate();
            result = menuDao.update(menu);
        }
        return result > 0;
    }

    @Transactional(readOnly = false)
    public boolean delete(Menu menu) {
        return menuDao.isExist(menu) != 0 && menuDao.delete(menu) > 0;
    }

	public Menu findDetail(Menu menu) {
		return menuDao.findDetail(menu);
	}

}
